//
//  Mine_ViewController.m
//  SSKJ
//
//  Created by 赵亚明 on 2018/12/11.
//  Copyright © 2018 刘小雨. All rights reserved.
//

#import "Mine_ViewController.h"
#import "Mine_HeaderView.h"
#import "Mine_TableViewCell.h"
@interface Mine_ViewController ()<UITableViewDelegate,UITableViewDataSource,Mine_HeaderViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) Mine_HeaderView *headerView;
@property (nonatomic, strong) NSArray *titlesArray;
@property (nonatomic, strong) NSArray *imagesArray;

@end

@implementation Mine_ViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.titlesArray = @[SSKJLocalized(@"个人中心", nil),
                             SSKJLocalized(@"安全中心", nil),
                             SSKJLocalized(@"资产管理", nil),
                             SSKJLocalized(@"挖矿明细", nil),
                             SSKJLocalized(@"提币地址", nil),
                             SSKJLocalized(@"经纪人", nil),
                             SSKJLocalized(@"平台公告", nil),
                             SSKJLocalized(@"关于我们", nil)];
        self.imagesArray = @[@"mine_center",
                             @"mine_safe",
                             @"mine_money_mangager",
                             @"mine_jjr",
                             @"mine_detail",
                             @"mine_addr",
                             @"mine_notice",
                             @"mine_about"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kMainColor;
    [self tableView];
    self.tableView.tableHeaderView = self.headerView;
    [self setupTableViewHeaderView];
}

#pragma mark --- privateHeader
- (void)setupTableViewHeaderView {
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.tableView);
    }];
    self.tableView.tableHeaderView = self.headerView;
    [self.tableView layoutIfNeeded];
    [self.tableView reloadData];
}

#pragma mark --- UITableViewDelegate --


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titlesArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ScaleH(56);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    Mine_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell configureCellWithTitle:self.titlesArray[indexPath.row]
                       imageName:self.imagesArray[indexPath.row]];
    return cell;
}

#pragma mark -- Mine_HeaderViewDelegate
- (void)clickWithButton:(UIButton *)button {
    NSLog(@"登录");
    [self.headerView configureViewWithIsLogin:YES];
    [self setupTableViewHeaderView];
}
- (void)logoutClickButton:(UIButton *)button {
    NSLog(@"登出");
    [self.headerView configureViewWithIsLogin:NO];
    [self setupTableViewHeaderView];
}
#pragma mark -- 懒加载 --
- (Mine_HeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[Mine_HeaderView alloc]init];
        _headerView.delegate = self;
    }
    return _headerView;
}
#pragma mark -- 创建表 --
- (UITableView *)tableView{
    if (!_tableView) {

        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableFooterView = [UIView new];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _tableView.estimatedRowHeight = 0;
            _tableView.estimatedSectionHeaderHeight = 0;
            _tableView.estimatedSectionFooterHeight = 0;
        }
        else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        [_tableView registerClass:[Mine_TableViewCell class] forCellReuseIdentifier:@"cell"];
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.left.equalTo(@0);
            make.width.equalTo(@(ScreenWidth));
            make.height.equalTo(@(ScreenHeight-Height_TabBar));
        }];
        UIImageView *imgView = [UIImageView new];
        imgView.image = [UIImage imageNamed:@"mine_bg_bottom"];
        [self.view addSubview:imgView];
        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.view);
            make.bottom.equalTo(self.view).offset(-Height_TabBar);
            make.height.equalTo(@(ScaleH(120)));
            make.width.mas_equalTo(ScreenWidth);
        }];
    }
    return _tableView;
}

#pragma mark - 页面即将呈现
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
